<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Ha Anh Son
 * Date: 4/8/13
 * Time: 2:36 PM
 * To change this template use File | Settings | File Templates.
 */
class Crawler {
    protected $content= '';

    public function __construct($uri) {
        $this->content= $this->getContent($uri);
    }

    public function getContent($uri) {
        return file_get_contents($uri);
    }

    public function get($type) {
        $method = "_get_{$type}";
        if (method_exists($this, $method)){
            return call_user_func(array($this, $method));
        }
    }

    protected function _get_images() {
        if (!empty($this->content)){
            preg_match_all('/]+)\/>/i', $this->content, $images);
            return !empty($images[1]) ? $images[1] : FALSE;
        }
    }

    protected function _get_links() {
        if (!empty($this->content)){
            preg_match_all('/]+)\>(.*?)\<\/a\>/i', $this->content, $links);
            return !empty($links[1]) ? $links[1] : FALSE;
        }
    }
}